﻿using MoreEvent.Common.Systems;
using MoreEvent.Content.Biomes;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;

namespace MoreEvent.Common.GlobalNPCs
{
    public class DialogueNPC : GlobalNPC
    {
        public override bool InstancePerEntity => true;
        protected override bool CloneNewInstances => true;
        private List<string> chat2 = [];
        private static List<string> textlist = [];
        public override void GetChat(NPC npc, ref string chat)
        {
            int num = 6;
            chat2 = GetText(npc, ref num, Main.LocalPlayer);
            if (Main.rand.Next(num + chat2.Count) > num - 1)
            {
                chat = chat2[Main.rand.Next(chat2.Count)];
            }
        }
        public static List<string> GetText(NPC npc, ref int dialogue, Player player)
        {
            textlist.Clear();
            if (npc.type == NPCID.Angler)
            {
                if (player.InModBiome<MeteorShower>())
                {
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Angler.1"));
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Angler.2"));
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Angler.3"));
                }
                if (EventSystem.ActiveEvents.Contains(2))
                {
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Angler.4"));
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Angler.5"));
                }
            }
            if (npc.type == NPCID.ArmsDealer)
            {
                if (player.InModBiome<MeteorShower>())
                {
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.ArmsDealer.1"));
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.ArmsDealer.2"));
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.ArmsDealer.3"));
                }
                if (EventSystem.ActiveEvents.Contains(2))
                {
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.ArmsDealer.4"));
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.ArmsDealer.5"));
                }
            }
            if (npc.type == NPCID.Clothier)
            {
                if (EventSystem.ActiveEvents.Contains(2))
                {
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Clothier.1"));
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Clothier.2"));
                }
            }
            if (npc.type == NPCID.Demolitionist)
            {
                if (EventSystem.ActiveEvents.Contains(2))
                {
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Demolitionist.1"));
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Demolitionist.2"));
                }
            }
            if (npc.type == NPCID.Dryad)
            {
                if (EventSystem.ActiveEvents.Contains(2))
                {
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Dryad.1"));
                    textlist.Add(Language.GetTextValue("Mods.MoreEvent.Dialogue.Dryad.2"));
                }
            }
            return textlist;
        }
    }
}
